package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @AutoFill(value = OperationType.INSERT)
    @Insert( "insert into setmeal (category_id,name, price, status, description,image,create_time,update_time,create_user,update_user)"+
            "  values (#{categoryId},#{name}, #{price}, #{status}, #{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void add(Setmeal setmeal);

    @Select("select count(*) from setmeal")
    Long count(SetmealPageQueryDTO setmealPageQueryDTO);

    List<SetmealVO> selectByPage(SetmealPageQueryDTO setmealPageQueryDTO, Integer start);

    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Select("select * from setmeal where id = #{id}")
    Setmeal selectById(Long id);

    List<Integer> selectStatusByIds(List<Long> ids);

    void delete(List<Long> ids);
}
